package com.sparrow.manage.article;

import com.sparrow.manage.common.entity.Attachment;
import com.sparrow.manage.common.entity.StandardEntity;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.Date;
import java.util.Objects;

@Entity
@Table(name = "tb_article")
public class Article implements StandardEntity<String> {

    public enum ArticleType{
        COMPANY("公司简介", "0"),
        EVENT("要闻", "1"),
        BUSINESS("业务介绍", "2"),
        EMPLOYEE("员工介绍", "3"),
        PRODUCT("产品介绍", "4"),
        RECRUITMENT("招聘", "5");

        private final String name;

        private final String code;

        ArticleType(String name, String code){
            this.name = name;
            this.code = code;
        }

        public String getName() {
            return name;
        }

        public String getCode() {
            return code;
        }
    }

    @Id
    @Column(name = "ID_", length = 36)
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid")
    private String id;  // 主键

    @Column(name = "title_", length = 100)
    private String title;   // 标题

    @Column(name = "sub_title", length = 100)
    private String subTitle;    // 副标题

    @Column(name = "author", length = 20)
    private String author;  // 作者

    @Column(name = "type", length = 10)
    private String type;

    @Column(name = "carousel", length = 1)
    private Integer carousel;   // 标记是否是轮播图: 0 否, 1 是

    @Column(name = "outline", columnDefinition = "Text")
    private String outline; // 梗概

    @Column(name = "content", columnDefinition = "Text")
    private String content; // 内容, 大字段, 富文本

    @Column(name = "priority", length = 2)
    private Integer priority;   // 优先级

    @Column(name = "create_user", length = 36, updatable = false)
    private String createUser;

    @Column(name = "update_user",  length = 36)
    private String updateUser;

    @Column(name = "create_time", updatable = false)
    private Date createTime;

    @Column(name = "update_time")
    private Date updateTime;

    @Transient
    private Attachment headImage;

    public Attachment getHeadImage() {
        return headImage;
    }

    public void setHeadImage(Attachment headImage) {
        this.headImage = headImage;
    }

    @Override
    public String getCreateUser() {
        return createUser;
    }

    @Override
    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }

    @Override
    public String getUpdateUser() {
        return updateUser;
    }

    @Override
    public void setUpdateUser(String updateUser) {
        this.updateUser = updateUser;
    }

    @Override
    public Date getCreateTime() {
        return createTime;
    }

    @Override
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    @Override
    public Date getUpdateTime() {
        return updateTime;
    }

    @Override
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public String getOutline() {
        return outline;
    }

    public void setOutline(String outline) {
        this.outline = outline;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getSubTitle() {
        return subTitle;
    }

    public void setSubTitle(String subTitle) {
        this.subTitle = subTitle;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Integer getCarousel() {
        return carousel;
    }

    public void setCarousel(Integer carousel) {
        this.carousel = carousel;
    }

    public Integer getPriority() {
        return priority;
    }

    public void setPriority(Integer priority) {
        this.priority = priority;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Article article = (Article) o;
        return StringUtils.isNotBlank(article.id) && article.id.equals(this.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, title, subTitle, author, type, carousel, outline, content, priority, createUser, updateUser, createTime, updateTime, headImage);
    }
}
